<template>
	<view class="container">
		<!-- 页面头部 -->
		<view class="header">
			<view class="title">学习计划</view>
			<view class="subtitle">制定计划，稳步提升裁判技能</view>
		</view>
		
		<!-- 计划概览 -->
		<view class="plan-overview">
			<view class="overview-item">
				<view class="item-value">{{completedCount}}</view>
				<view class="item-label">已完成</view>
			</view>
			<view class="overview-item">
				<view class="item-value">{{inProgressCount}}</view>
				<view class="item-label">进行中</view>
			</view>
			<view class="overview-item">
				<view class="item-value">{{totalHours}}</view>
				<view class="item-label">总学时</view>
			</view>
		</view>
		
		<!-- 计划切换 -->
		<view class="plan-tabs">
			<view 
				class="tab-item" 
				v-for="(item, index) in planTabs" 
				:key="index"
				:class="{active: currentTab === index}"
				@click="switchTab(index)"
			>
				<text>{{item}}</text>
			</view>
		</view>
		
		<!-- 计划列表 -->
		<scroll-view scroll-y class="plan-list-scroll">
			<view class="plan-list">
				<view class="plan-item" v-for="(item, index) in filteredPlans" :key="index">
					<view class="plan-content" @click="togglePlanDetail(index)">
						<view class="plan-title-row">
							<view class="plan-title">{{item.title}}</view>
							<view class="plan-status" :class="{
								'status-completed': item.status === 'completed',
								'status-in-progress': item.status === 'in_progress',
								'status-not-started': item.status === 'not_started'
							}">
								<text>{{getStatusText(item.status)}}</text>
							</view>
						</view>
						<view class="plan-desc">{{item.description}}</view>
						<view class="plan-meta">
							<view class="meta-item">
								<text class="meta-icon">⏱️</text>
								<text class="meta-text">{{item.duration}}小时</text>
							</view>
							<view class="meta-item">
								<text class="meta-icon">📆</text>
								<text class="meta-text">{{formatDate(item.start_date)}} - {{formatDate(item.end_date)}}</text>
							</view>
						</view>
						<view class="progress-bar" v-if="item.status !== 'not_started'">
							<view class="progress-inner" :style="{width: item.progress + '%'}"></view>
							<text class="progress-text">{{item.progress}}%</text>
						</view>
					</view>
					
					<!-- 展开的学习计划详情 -->
					<view class="plan-detail" v-if="item.showDetail">
						<view class="detail-title">学习内容</view>
						<view class="task-list">
							<view class="task-item" v-for="(task, taskIndex) in item.tasks" :key="taskIndex">
								<view class="task-checkbox" @click="toggleTaskStatus(index, taskIndex)">
									<text class="checkbox-icon" :class="{'checkbox-checked': task.completed}">
										{{task.completed ? '✓' : ''}}
									</text>
								</view>
								<view class="task-content" :class="{'task-completed': task.completed}">
									<view class="task-name">{{task.name}}</view>
									<view class="task-desc">{{task.description}}</view>
								</view>
							</view>
						</view>
						
						<view class="detail-actions">
							<button class="action-btn primary" v-if="item.status !== 'completed'" @click="startLearning(item)">
								{{item.status === 'not_started' ? '开始学习' : '继续学习'}}
							</button>
							<button class="action-btn secondary" @click="editPlan(item)">编辑计划</button>
						</view>
					</view>
				</view>
				
				<view v-if="filteredPlans.length === 0" class="empty-tip">
					<text>暂无{{planTabs[currentTab]}}，点击下方按钮创建</text>
				</view>
			</view>
		</scroll-view>
		
		<!-- 创建计划按钮 -->
		<view class="floating-btn" @click="createNewPlan">
			<text class="btn-icon">+</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				planTabs: ['全部计划', '进行中', '已完成', '未开始'],
				currentTab: 0,
				plans: [],
				completedCount: 0,
				inProgressCount: 0,
				totalHours: 0
			}
		},
		computed: {
			filteredPlans() {
				if (this.currentTab === 0) {
					return this.plans;
				} else if (this.currentTab === 1) {
					return this.plans.filter(plan => plan.status === 'in_progress');
				} else if (this.currentTab === 2) {
					return this.plans.filter(plan => plan.status === 'completed');
				} else {
					return this.plans.filter(plan => plan.status === 'not_started');
				}
			}
		},
		onLoad() {
			// 获取学习计划数据
			this.loadPlans();
		},
		methods: {
			// 切换选项卡
			switchTab(index) {
				this.currentTab = index;
			},
			
			// 加载学习计划
			loadPlans() {
				// 模拟数据
				this.plans = [
					{
						id: '1',
						title: '足球规则基础学习',
						description: '学习足球比赛的基本规则和概念',
						status: 'completed',
						progress: 100,
						duration: 10,
						start_date: '2023-01-01',
						end_date: '2023-01-15',
						showDetail: false,
						tasks: [
							{
								name: '学习比赛场地规则',
								description: '了解比赛场地的尺寸、标记和装备要求',
								completed: true
							},
							{
								name: '学习球员和装备规则',
								description: '了解球员人数、替换规则和装备要求',
								completed: true
							},
							{
								name: '学习比赛时间规则',
								description: '了解比赛时长、中场休息和补时规则',
								completed: true
							},
							{
								name: '学习进球规则',
								description: '了解进球有效性的判定规则',
								completed: true
							},
							{
								name: '完成规则基础测试',
								description: '通过在线测试检验学习成果',
								completed: true
							}
						]
					},
					{
						id: '2',
						title: '裁判手势与信号',
						description: '学习并掌握裁判在比赛中使用的各种手势和信号',
						status: 'in_progress',
						progress: 60,
						duration: 15,
						start_date: '2023-02-01',
						end_date: '2023-02-28',
						showDetail: false,
						tasks: [
							{
								name: '学习基本裁判手势',
								description: '了解比赛开始、结束、进球等基本手势',
								completed: true
							},
							{
								name: '学习犯规手势',
								description: '了解不同类型犯规的示意手势',
								completed: true
							},
							{
								name: '学习位置越位手势',
								description: '了解越位的判罚和示意手势',
								completed: true
							},
							{
								name: '学习替换和时间手势',
								description: '了解球员替换和补时的示意手势',
								completed: false
							},
							{
								name: '实战演练和测试',
								description: '通过实战模拟和测试检验手势掌握情况',
								completed: false
							}
						]
					},
					{
						id: '3',
						title: '高级比赛规则',
						description: '深入学习比赛中的高级规则和复杂情况判罚',
						status: 'not_started',
						progress: 0,
						duration: 20,
						start_date: '2023-03-15',
						end_date: '2023-04-15',
						showDetail: false,
						tasks: [
							{
								name: '学习高级犯规判罚',
								description: '了解复杂犯规情况的判罚标准',
								completed: false
							},
							{
								name: '学习战术犯规处理',
								description: '了解战术犯规的识别和处罚',
								completed: false
							},
							{
								name: '学习点球判罚',
								description: '了解点球的判罚标准和执行流程',
								completed: false
							},
							{
								name: '学习VAR技术应用',
								description: '了解助理裁判的使用规则',
								completed: false
							},
							{
								name: '高级规则测试',
								description: '通过综合测试检验高级规则掌握情况',
								completed: false
							}
						]
					}
				];
				
				// 计算统计数据
				this.calculateStatistics();
			},
			
			// 计算统计数据
			calculateStatistics() {
				this.completedCount = this.plans.filter(plan => plan.status === 'completed').length;
				this.inProgressCount = this.plans.filter(plan => plan.status === 'in_progress').length;
				
				// 计算总学时（已完成的计入全部，进行中的按进度比例计入）
				let hours = 0;
				this.plans.forEach(plan => {
					if (plan.status === 'completed') {
						hours += plan.duration;
					} else if (plan.status === 'in_progress') {
						hours += plan.duration * (plan.progress / 100);
					}
				});
				this.totalHours = Math.round(hours);
			},
			
			// 展开/收起计划详情
			togglePlanDetail(index) {
				this.$set(this.filteredPlans[index], 'showDetail', !this.filteredPlans[index].showDetail);
			},
			
			// 切换任务完成状态
			toggleTaskStatus(planIndex, taskIndex) {
				const plan = this.filteredPlans[planIndex];
				const task = plan.tasks[taskIndex];
				
				// 切换任务完成状态
				task.completed = !task.completed;
				
				// 更新计划进度
				const completedCount = plan.tasks.filter(t => t.completed).length;
				plan.progress = Math.round((completedCount / plan.tasks.length) * 100);
				
				// 更新计划状态
				if (plan.progress === 100) {
					plan.status = 'completed';
				} else if (plan.progress === 0) {
					plan.status = 'not_started';
				} else {
					plan.status = 'in_progress';
				}
				
				// 重新计算统计数据
				this.calculateStatistics();
				
				// 实际应用中应该保存到服务器
				// this.savePlanData();
			},
			
			// 开始/继续学习
			startLearning(plan) {
				// 查找第一个未完成的任务
				const firstUncompletedTask = plan.tasks.find(task => !task.completed);
				
				if (firstUncompletedTask) {
					// 实际应用中应该跳转到相应的学习内容页面
					uni.showToast({
						title: '正在准备学习：' + firstUncompletedTask.name,
						icon: 'none',
						duration: 2000
					});
				}
			},
			
			// 编辑计划
			editPlan(plan) {
				uni.showToast({
					title: '编辑计划功能开发中',
					icon: 'none',
					duration: 2000
				});
			},
			
			// 创建新计划
			createNewPlan() {
				uni.showToast({
					title: '创建计划功能开发中',
					icon: 'none',
					duration: 2000
				});
			},
			
			// 格式化日期
			formatDate(dateStr) {
				if (!dateStr) return '';
				const date = new Date(dateStr);
				return `${date.getMonth() + 1}月${date.getDate()}日`;
			},
			
			// 获取状态文本
			getStatusText(status) {
				switch(status) {
					case 'completed':
						return '已完成';
					case 'in_progress':
						return '进行中';
					case 'not_started':
						return '未开始';
					default:
						return '未知';
				}
			}
		}
	}
</script>

<style>
	.container {
		min-height: 100vh;
		background-color: #F8F8F8;
		display: flex;
		flex-direction: column;
	}
	
	/* 头部样式 */
	.header {
		background-color: #1BAE76;
		padding: 40rpx 30rpx;
		color: #FFFFFF;
	}
	
	.title {
		font-size: 36rpx;
		font-weight: bold;
		margin-bottom: 10rpx;
	}
	
	.subtitle {
		font-size: 24rpx;
		opacity: 0.8;
	}
	
	/* 计划概览样式 */
	.plan-overview {
		display: flex;
		background-color: #FFFFFF;
		padding: 30rpx 0;
		border-bottom: 1rpx solid #EEEEEE;
	}
	
	.overview-item {
		flex: 1;
		text-align: center;
		position: relative;
	}
	
	.overview-item:not(:last-child):after {
		content: '';
		position: absolute;
		right: 0;
		top: 20%;
		height: 60%;
		width: 1rpx;
		background-color: #EEEEEE;
	}
	
	.item-value {
		font-size: 40rpx;
		font-weight: bold;
		color: #1BAE76;
		margin-bottom: 10rpx;
	}
	
	.item-label {
		font-size: 24rpx;
		color: #999999;
	}
	
	/* 计划切换样式 */
	.plan-tabs {
		display: flex;
		background-color: #FFFFFF;
		padding: 20rpx 0;
		border-bottom: 1rpx solid #EEEEEE;
	}
	
	.tab-item {
		flex: 1;
		text-align: center;
		font-size: 28rpx;
		color: #666666;
		position: relative;
		padding: 10rpx 0;
	}
	
	.tab-item.active {
		color: #1BAE76;
		font-weight: bold;
	}
	
	.tab-item.active:after {
		content: '';
		position: absolute;
		bottom: -10rpx;
		left: 50%;
		transform: translateX(-50%);
		width: 40rpx;
		height: 4rpx;
		background-color: #1BAE76;
	}
	
	/* 计划列表样式 */
	.plan-list-scroll {
		flex: 1;
	}
	
	.plan-list {
		padding: 20rpx;
	}
	
	.plan-item {
		background-color: #FFFFFF;
		border-radius: 10rpx;
		margin-bottom: 20rpx;
		overflow: hidden;
		box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
	}
	
	.plan-content {
		padding: 30rpx;
	}
	
	.plan-title-row {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 10rpx;
	}
	
	.plan-title {
		font-size: 32rpx;
		font-weight: bold;
		color: #333333;
	}
	
	.plan-status {
		padding: 4rpx 16rpx;
		border-radius: 30rpx;
		font-size: 22rpx;
	}
	
	.status-completed {
		background-color: rgba(64, 158, 255, 0.1);
		color: #409EFF;
	}
	
	.status-in-progress {
		background-color: rgba(0, 127, 79, 0.1);
		color: #1BAE76;
	}
	
	.status-not-started {
		background-color: rgba(144, 147, 153, 0.1);
		color: #909399;
	}
	
	.plan-desc {
		font-size: 28rpx;
		color: #666666;
		margin-bottom: 20rpx;
		line-height: 1.5;
	}
	
	.plan-meta {
		display: flex;
		margin-bottom: 20rpx;
	}
	
	.meta-item {
		display: flex;
		align-items: center;
		margin-right: 30rpx;
	}
	
	.meta-icon {
		font-size: 24rpx;
		margin-right: 6rpx;
	}
	
	.meta-text {
		font-size: 24rpx;
		color: #999999;
	}
	
	.progress-bar {
		height: 30rpx;
		background-color: #F5F5F5;
		border-radius: 15rpx;
		overflow: hidden;
		position: relative;
	}
	
	.progress-inner {
		height: 100%;
		background-color: #1BAE76;
		border-radius: 15rpx;
	}
	
	.progress-text {
		position: absolute;
		right: 10rpx;
		top: 0;
		line-height: 30rpx;
		font-size: 20rpx;
		color: #FFFFFF;
	}
	
	/* 计划详情样式 */
	.plan-detail {
		background-color: #F9F9F9;
		padding: 30rpx;
		border-top: 1rpx solid #EEEEEE;
	}
	
	.detail-title {
		font-size: 28rpx;
		font-weight: bold;
		color: #333333;
		margin-bottom: 20rpx;
	}
	
	.task-list {
		margin-bottom: 30rpx;
	}
	
	.task-item {
		display: flex;
		margin-bottom: 20rpx;
	}
	
	.task-checkbox {
		width: 40rpx;
		height: 40rpx;
		margin-right: 20rpx;
		flex-shrink: 0;
	}
	
	.checkbox-icon {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 40rpx;
		height: 40rpx;
		border: 2rpx solid #DDDDDD;
		border-radius: 6rpx;
		color: #FFFFFF;
		font-size: 24rpx;
	}
	
	.checkbox-checked {
		background-color: #1BAE76;
		border-color: #1BAE76;
	}
	
	.task-content {
		flex: 1;
	}
	
	.task-completed {
		opacity: 0.6;
	}
	
	.task-name {
		font-size: 28rpx;
		color: #333333;
		margin-bottom: 6rpx;
		font-weight: bold;
	}
	
	.task-desc {
		font-size: 24rpx;
		color: #666666;
		line-height: 1.5;
	}
	
	.detail-actions {
		display: flex;
		justify-content: space-between;
	}
	
	.action-btn {
		flex: 1;
		margin: 0 10rpx;
		height: 80rpx;
		line-height: 80rpx;
		font-size: 28rpx;
		border-radius: 40rpx;
	}
	
	.action-btn.primary {
		background-color: #1BAE76;
		color: #FFFFFF;
		border: none;
	}
	
	.action-btn.secondary {
		background-color: #FFFFFF;
		color: #1BAE76;
		border: 1rpx solid #1BAE76;
	}
	
	/* 空数据提示 */
	.empty-tip {
		text-align: center;
		padding: 100rpx 0;
		color: #999999;
		font-size: 28rpx;
	}
	
	/* 浮动按钮 */
	.floating-btn {
		position: fixed;
		right: 40rpx;
		bottom: 40rpx;
		width: 100rpx;
		height: 100rpx;
		background-color: #1BAE76;
		color: #FFFFFF;
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
		box-shadow: 0 4rpx 10rpx rgba(0, 127, 79, 0.3);
		z-index: 10;
	}
	
	.btn-icon {
		font-size: 50rpx;
	}
</style> 